/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package beans.ejb;

import entities.Nflplayer;
import entities.Nflplayerseasonstat;
import java.util.HashMap;
import java.util.Iterator;
import java.util.List;
import javax.ejb.Stateless;
import javax.persistence.EntityManager;
import javax.persistence.NoResultException;
import javax.persistence.PersistenceContext;
import javax.persistence.Query;

/**
 *
 * @author stumbledog
 */
@Stateless
public class NflplayerseasonstatFacade extends AbstractFacade<Nflplayerseasonstat> {
    @PersistenceContext(unitName = "Touchdown308PU")
    private EntityManager em;
    
    private HashMap<Integer, Nflplayerseasonstat> map;
        
    @Override
    protected EntityManager getEntityManager() {
        return em;
    }

    public NflplayerseasonstatFacade() {
        super(Nflplayerseasonstat.class);
    }
    
    public Nflplayerseasonstat findStatByPlayerId(Nflplayer playerId){
        javax.persistence.criteria.CriteriaQuery cq = getEntityManager().getCriteriaBuilder().createQuery();
        Query q = getEntityManager().createNamedQuery("Nflplayerseasonstat.findByPlayerId");
        q.setParameter("playerId", playerId.getId());
        try {
            return (Nflplayerseasonstat)q.getSingleResult();
        } catch (NoResultException e) {
            return null;
        }
    }
    
    public HashMap<Integer, Nflplayerseasonstat> getStatMap(){
        if(map==null){
            map = new HashMap<Integer, Nflplayerseasonstat>();
            javax.persistence.criteria.CriteriaQuery cq = getEntityManager().getCriteriaBuilder().createQuery();
            Query q = getEntityManager().createNamedQuery("Nflplayerseasonstat.findAll");
            List<Nflplayerseasonstat> list = q.getResultList();
            Iterator<Nflplayerseasonstat> itr = list.iterator();
            while(itr.hasNext()){
                Nflplayerseasonstat tmp = itr.next();
                map.put(Integer.valueOf(tmp.getNflplayerseasonstatPK().getPlayerId()), tmp);
            }
        }
        return map;
    }
}
